﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Volo.Abp;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;

namespace Acme.BookStore2
{
    /// <summary>
    /// 车辆
    /// </summary>
    public class Vehicle : FullAuditedAggregateRoot<Guid>, IMultiTenant
    {
        /// <summary>
        /// 车辆编号
        /// </summary>
        public virtual string Number { get; set; }
        
        /// <summary>
        /// VIN
        /// </summary>
        public virtual string VIN { get; set; }
        
        /// <summary>
        /// 车牌号码
        /// </summary>
        public virtual string LicensePlateNumber { get; set; }
        
        /// <summary>
        /// 车辆品牌
        /// </summary>
        public virtual string Brand { get; set; }

        /// <summary>
        /// 车辆类型
        /// </summary>
        public virtual string VehicleType { get; set; }
        
        /// <summary>
        /// 车辆合作服务商
        /// </summary>
        public virtual string Partner { get; set; }
        
        /// <summary>
        /// 车辆年份
        /// </summary>
        public virtual DateTime? VehicleYear { get; set; }
        
        /// <summary>
        /// 车辆购入时间
        /// </summary>
        public virtual DateTime? PurchasingDate { get; set; }
        
        /// <summary>
        /// 轮胎类型
        /// </summary>
        public virtual string TireType { get; set; }
        
        /// <summary>
        /// 成本金额
        /// </summary>
        public virtual decimal CostAmount { get; set; }

        /// <summary>
        /// 成本详情
        /// </summary>
        public virtual string Cost { get; set; }

        /// <summary>
        /// 总燃油费用
        /// </summary>
        public virtual decimal TotalFuelCost { get; set; }
        
        /// <summary>
        /// 是否正在保养
        /// </summary>
        public virtual bool IsMaintaining { get; private set; }

        /// <summary>
        /// 备注
        /// </summary>
        public virtual string Remark { get; set; }
        
        /// <summary>
        /// 租户Id
        /// </summary>
        public Guid? TenantId { get; }

        /// <summary>
        /// 附件
        /// </summary>
        public virtual Collection<AttachFile> AttachFiles { get; set; }
        
        protected Vehicle()
        {
        }

        public Vehicle(Guid id, Guid? tenantId = null) : base(id)
        {
            AttachFiles = new Collection<AttachFile>();
            TenantId = tenantId;
            IsMaintaining = false;
        }

        /// <summary>
        /// 开始保养
        /// </summary>
        public void StartMaintenance()
        {
            IsMaintaining = true;
        }
        
        /// <summary>
        /// 结束保养
        /// </summary>
        public void EndMaintenance()
        {
            IsMaintaining = false;
        }
        
        /// <summary>
        /// 检查是否正在保养
        /// </summary>
        public void CheckMaintenance()
        {
            if (IsMaintaining)
            {
                throw new BusinessException(VehicleErrorCodes.IsMaintaining);
            }
        }
    }
}